﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Data;

namespace SqlPermissionsAuditor
{
           
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private SqlConnectionString _test;
        public List<CheckedListItem> AvailablePresentationObjects = new List<CheckedListItem>();

        public MainWindow()
        {
            InitializeComponent();
        }

        public SqlConnectionString Test
        {
            get { return _test; }
            set
            {
                _test = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Test"));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void btnGenerateScript_Click(object sender, RoutedEventArgs e)
        {
            var connectionString = ConnectionStringBuilder.ConnectionString;
            MessageBox.Show(connectionString.ToString());

            DataAccess dataAccess = new DataAccess(connectionString);
            var logins = dataAccess.ExecuteQuery(Resource1.EnumerateLogins);
            foreach (DataRow loginRow in logins.Tables[0].Rows)
            {
                AvailablePresentationObjects.Add(new CheckedListItem() {  Name = (string)loginRow["name"], IsChecked=true });
            }
            //select * from sys.users
            lstUsers.ItemsSource = AvailablePresentationObjects;
            //show all users before this?
            //Script script = new Script();
            //script.ShowDialog();
        }
    }
}
